<?php
require_once(ROOT. 'lib/Mailer/class.phpmailer.php');

class Mail{
  var $mailer;
  function __construct(){
    $this -> mailer = new PHPMailer();;
  }

  function setTitle($subject){
    $this -> mailer -> Subject = $subject?$subject:'hello';
  }

  function setBody($body, $type = null){
    if ($type == "html"){
      $this -> mailer -> MsgHTML($body);
    }else{
      $this -> mailer -> IsHTML(false);
      $this -> mailer -> Body = $body;
    }
  }

  function addBcc($mail){
    $emails = explode(",", $mail);
    foreach ($emails as $i){
      $this -> mailer -> AddBCC($i);
    }
  }

  function setFrom($fromEmail, $fromName = null){
    $this -> mailer -> From = $fromEmail;
    $this -> mailer -> FromName = $fromName?$fromName:'noticer';
  }

  function addTo($mail){
    $emails = explode(",", $mail);
    foreach ($emails as $i){
      $this -> mailer -> AddAddress($i);
    }
  }

  function attachFile($file){
    $this -> mailer -> AddAttachment($file); // attachment
  }

  function addImageEmbed($file, $name1 = null, $name2 = null){ 
    // $mail->AddEmbeddedImage(ROOT."public/images/logo7.png","logo","logo7.png");
    $this -> mailer -> AddEmbeddedImage($file, $name1, $name2);
  }

  function send(){
    $this -> mailer -> IsSendmail(); // telling the class to use SendMail transport
    $this -> mailer -> AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
    if (!$this -> mailer -> Send()){
      return "Mailer Error: " . $this -> mailer -> ErrorInfo;
    }else{
      return "Message sent!";
    }
  }
}

?>